import com.sun.org.apache.xerces.internal.impl.xs.SchemaNamespaceSupport;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2023-02-27
 * Time: 10:37
 */
class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
        this.val = val;
    }
}
public class Day18 {
    //70.爬楼梯 - 标记
    //时间：O(n) 空间：O(1)
    public int climbStairs(int n) {
        int f0 = 0, f1 = 0, f2 = 1;
        for (int i = 1; i <= n; i++) {
            f0 = f1;
            f1 = f2;
            f2 = f0 + f1;
        }
        return f2;
    }
    //时间：O(1) 空间：O(1)
    public int climbStairs2(int n) {
        double sqrt5 = Math.sqrt(5);
        double fibn = Math.pow((1 + sqrt5) / 2, n + 1) - Math.pow((1 - sqrt5) / 2, n + 1);

        return (int)Math.round(fibn / sqrt5);
    }
    //338.比特位计数 - 标记
    public int[] countBits(int n) {
        int[] answer = new int[n + 1];

        for (int i = 0; i <= n; i++) {
            if (i % 2 == 0){
                //偶数就是一个数*2，那么二进制位对应1个数相等
                answer[i] = answer[i / 2];
            }else{
                //奇数 = 偶数 + 1
                answer[i] = answer[i / 2] + 1;
            }
        }

        return answer;
    }
    //509.斐波那契数
    public int fib(int n) {
        int f0 = 0, f1 = 0, f2 = 1;

        if (n == 0){
            return 0;
        }
        for (int i = 1; i < n; i++) {
            f0 = f1;
            f1 = f2;
            f2 = f0 + f1;
        }
        return f2;
    }
    //1025.除数博弈
    public boolean divisorGame(int n) {
        return n % 2 == 0;
    }
    //1137.第N个泰波那契数 -- 标记
    public int tribonacci(int n) {
        if (n == 0){
            return 0;
        }else if (n == 1){
            return 1;
        }else if (n == 2){
            return 1;
        }
        int f0 = 0, f1 = 1, f2 = 1, ret = 2;
        for (int i = 3; i < n; i++) {
            f0 = f1;
            f1 = f2;
            f2 = ret;

            ret = f0 + f1 + f2;
        }
        return ret;
    }
    //1646.获取生成数组中最大值
    public int getMaximumGenerated(int n) {
        int[] ret = new int[n + 1];

        if (n == 0){
            return 0;
        }
        if (n == 1){
            return 1;
        }
        int max = 0;
        ret[0] = 0;
        ret[1] = 1;
        for (int i = 2; i < ret.length; i++) {
            if (i % 2 == 0){
                ret[i] = ret[i / 2];
            }else{
                ret[i] = ret[(i - 1) / 2] + ret[(i - 1) / 2 + 1];
            }
            if (ret[i] > max){
                max = ret[i];
            }
        }

        return max;
    }
    //二叉树的左叶子之和
    public int Sum(TreeNode root){
        if (root == null){
            return 0;
        }
        int cnt = 0;
        if (root.left != null && root.left.right == null && root.right.left == null){
            cnt = root.left.val;
        }

        return cnt + Sum(root.left) + Sum(root.right);
    }
    public int sumOfLeftLeaves (TreeNode root) {
        return Sum(root);
    }

    //环形链表的约瑟夫问题
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int m = scanner.nextInt();
        int n = scanner.nextInt();

        int ret = 0;
        for (int i = 2; i <= n; i++) {
            ret = (ret + m) % i;
        }
        System.out.println(ret + 1);
    }
}
